package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.result.ResultCodeEnum;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import com.atguigu.tingshu.vo.album.AlbumCategoryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"unchecked", "rawtypes"})
public class BaseCategoryApiController {
	
	@Autowired
	private BaseCategoryService baseCategoryService;

	/**
	 * 通过GET请求获取基础分类列表。
	 *
	 * @return Result<List<AlbumCategoryVo>> 包含基础分类列表的结果对象，成功时返回ResultCodeEnum.SUCCESS代码。
	 */
	@GetMapping("/getBaseCategoryList")
	public Result<List<AlbumCategoryVo>> getBaseCategoryList() {
		List<AlbumCategoryVo> albumCategoryVoList = baseCategoryService.getBaseCategoryList();
		return Result.build(albumCategoryVoList, ResultCodeEnum.SUCCESS);
	}

	@GetMapping("/findAttribute/{category1Id}")
	public Result<List<BaseAttribute>> findAttributeByCategoryId(@PathVariable("category1Id") Long 	categoryId	) {

	 List<BaseAttribute>  baseAttributeList =	baseCategoryService.findAttributeByCategoryId(categoryId);
	return Result.build(baseAttributeList, ResultCodeEnum.SUCCESS);
	}


	@GetMapping("/findCategoryByC3Id/{c3Id}")
	public Result<BaseCategoryView> findCategoryByC3Id(@PathVariable("c3Id") Long c3Id) {
		BaseCategoryView baseCategoryView = baseCategoryService.getBaseCategoryView(c3Id);
		return Result.build(baseCategoryView, ResultCodeEnum.SUCCESS);
	}
	@Operation(summary = "根据一级分类id获取全部分类信息")
	@GetMapping("/getBaseCategoryList/{category1Id}")
	public Result<AlbumCategoryVo> getBaseCategoryList(@PathVariable(value = "category1Id") Long category1Id){
		AlbumCategoryVo albumCategoryVo = baseCategoryService.getAllCategoryList(category1Id);
		return Result.ok(albumCategoryVo);
	}

	@Operation(summary = "根据一级分类id查询置顶三级分类")
	@GetMapping("findTopBaseCategory3/{category1Id}")
	public Result<List<BaseCategory3>> findTopBaseCategory3(@PathVariable("category1Id") Long category1Id) {
		//	获取三级分类列表
		List<BaseCategory3> baseCategory3List = baseCategoryService.findTopBaseCategory3ByCategory1Id(category1Id);
		//	返回数据
		return Result.ok(baseCategory3List);
	}


}

